package m202406.d11;

import java.util.Arrays;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/6/11 17:54
 */
public class Q75 {
    public void sortColors(int[] nums) {
        int index = 0;
        //先找到0
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                swap(nums, i, index);
                index++;
            }
        }
        //然后找到1
        for (int i = index; i < nums.length; i++) {
            if (nums[i] == 1) {
                swap(nums, i, index);
                index++;
            }
        }
    }

    private void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
